package com.TPNexus.dao;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.hibernate.Session;
import org.junit.Test;

import com.TPNexus.model.CatalogItem;
import com.TPNexus.model.Product;
import com.TPNexus.model.ShoppingCart;
import com.TPNexus.model.ShoppingCartItem;

public class TestDataGenerator {

	@Test
	public void testSetProduct() throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		for (int i = 0; i < 10; i++) {
			Product product = new Product();
			product.setDescription("product " + UUID.randomUUID());
			product.setName("product " + i);
			product.setStatus(true);
			long id=(Long) session.save(product);
			System.out.println(id);
		}

		session.getTransaction().commit();
		HibernateUtil.getSessionFactory().close();

	}
	
	@Test
	public void testSetcatalog() throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		for (long i = 4; i < 7; i++) {
			Product product = (Product) session.get(Product.class, (long)3);
			CatalogItem c=new CatalogItem();
			c.setCurrency("SGD");
			c.setPrice(i+3.5);
			c.setProduct(product);
			c.setStatus(true);
			c.setSupplierId(1);
			session.save(c);
		}

		session.getTransaction().commit();
		HibernateUtil.getSessionFactory().close();

	}
	
	@Test
	public void testSetshoppingcartitem() throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		for (long i = 2; i < 6; i++) {
			CatalogItem c=(CatalogItem) session.get(CatalogItem.class, (long)i);
			ShoppingCartItem sci=new ShoppingCartItem();
			sci.setCatalogItem(c);
			sci.setQty((int) (i*10));
			session.save(sci);
		}

		session.getTransaction().commit();
		HibernateUtil.getSessionFactory().close();

	}
	
	
	@Test
	public void testSetshoppingcart() throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		ShoppingCart sc=new ShoppingCart();
		sc.setUserId(1);
		List<ShoppingCartItem> ssc=new ArrayList<ShoppingCartItem>();
		for (long i = 2; i < 6; i++) {
			
			ShoppingCartItem sci=(ShoppingCartItem) session.get(ShoppingCartItem.class, (long)(i-1));
			ssc.add(sci);

			
			
			
		}
		sc.setShoppingCartItems(ssc);
		session.save(sc);
		session.getTransaction().commit();
		HibernateUtil.getSessionFactory().close();

	}
}


